﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Frogism.Core {

  public static class DayExtensions {

    public static int WeekStartDaysAgo(this DateTime currentDate) {

      switch(currentDate.DayOfWeek) {
        case DayOfWeek.Sunday:
          return 0;
        case DayOfWeek.Monday:
          return 1;
        case DayOfWeek.Tuesday:
          return 2;
        case DayOfWeek.Wednesday:
          return 3;
        case DayOfWeek.Thursday:
          return 4;
        case DayOfWeek.Friday:
          return 5;
        default:
          return 6;
      }
    }
    public static DateTime StartOfWeek(this DateTime currentDate) {
      return CleanDate(currentDate.AddDays(-1 * WeekStartDaysAgo(currentDate)));
    }

    public static DateTime EndOfWeek(this DateTime currentDate) {
      return CleanDate(currentDate.AddDays(6 - WeekStartDaysAgo(currentDate)));
    }
    public static DateTime StartOfMonth(this DateTime currentDate) {
      return new DateTime(currentDate.Year, currentDate.Month, 1, 0, 0, 0);
    }
    public static DateTime EndOfMonth(this DateTime currentDate) {
      return StartOfMonth(currentDate).AddMonths(1).AddDays(-1);
    }
    public static DateTime StartOfYear(this DateTime currentDate) {
      return (new DateTime(currentDate.Year, 1, 1, 0, 0, 0));
    }
    public static DateTime EndOfYear(this DateTime currentDate) {
      return StartOfYear(currentDate).AddYears(1).AddDays(-1);
    }
    public static DateTime CleanDate(this DateTime date) {
      return new DateTime(date.Year, date.Month, date.Day, 0, 0, 0);
    }
   
  }

}
